#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;
//TODO

int main() 
{ 
	//TODO
	vector<vector<string>> lines;
    vector<string> strings;
	string line;
	while (getline(cin, line)){
        if (line.size()==0)break;
		strings.clear();
		string temp="";
		for (int i=0; i<line.size(); i++){
			if (line[i]==' '||line[i]=='\n'){
				strings.push_back(temp);
				temp="";
			}
			else{
				temp+=line[i];
			}
		}
		if (temp!="")strings.push_back(temp);
		lines.push_back(strings);
	}
	// for (int i=0; i<lines.size();i++){
	// 	cout<<i+1<<endl;
	// 	for (int j=0; j<lines[i].size();j++){
	// 		cout<<lines[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	
    
	map<string, vector<int>> maps;
	for (int i=0;i<lines.size();i++){
		
		for (int j=0; j<lines[i].size(); j++){
            
			maps[lines[i][j]].push_back(i+1);
			
        }
	}

	for (auto it=maps.begin(); it!=maps.end(); it++){
		cout<<it->first;
        vector<int> ints = it->second;
		//cout<<": "<<ints.size()<<":";
		int tag=-1;
		for (int i=0; i<ints.size(); i++){
			if (tag!=ints[i]){
				cout<<" "<<ints[i];
				tag=ints[i];
			}
		}
		cout<<endl;
	}
	return 0; 
}
